package chapter5;
import java.util.Scanner;
/****************************************************************
 * Author：icynlau
 * Description:  找出最高分和次高分  不过就是比上一道题目多了两个变量
 * 
 * 			可以改进的是，在姓名和分数交换时只声明两种类型的 交换用的临时变量tmp，
 * 			不需要循环内再声明一次了
 * Date:2021/4/3
 * ***************************************************************
 */
public class exc5_9 {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		System.out.print("Enter the number of students:  ");
		int nStudents=input.nextInt();
		System.out.print("Enter the name , score: ");
		String name=input.next();		//这行语句对名字中间有空格的情况无法处理，会出现错误
		double maxScore=input.nextDouble();
		System.out.print("Enter the next name , score: ");
		String name2=input.next();		//这行语句对名字中间有空格的情况无法处理，会出现错误
		double maxScore2=input.nextDouble();
		
		if(maxScore2>maxScore) {
			String stmp=name2;
			name2=name;
			name=stmp;
			
			double dtmp=maxScore2;
			maxScore2=maxScore;
			maxScore=dtmp;
		}
		
		for(int i=1;i<nStudents-1;i++) {
			System.out.print("Enter the next name , score: ");
			String nextName=input.next();		//这行语句对名字中间有空格的情况无法处理，会出现错误
			double nextMaxScore=input.nextDouble();
			if(nextMaxScore>maxScore2&&nextMaxScore<maxScore) {
//				System.out.println("nextMaxScore>maxScore2&&nextMaxScore<maxScore\n");
				name2=nextName;
				maxScore2=nextMaxScore;
			}
			if(nextMaxScore>maxScore) {
//				System.out.println("nextMaxScore>maxScore\n");
				String tmp=name;
				name=nextName;
				name2=tmp;
				
				double tmp2=maxScore;
				maxScore=nextMaxScore;
				maxScore2=tmp2;
			}
		}
		
		System.out.printf("The student who got  high Score are  : No.1 %s  and No.2 %s\n", name,name2);
	}
}
